<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text">
    <span >请输入用户名</span>
    <script>
        const inp = document.querySelector('input');
        const span = document.querySelector('span');
        // let reg = /^[0-9a-zA-Z]{6,16}$/;
        let reg = /^(ab){3}c$/;

        inp.onblur = function() {
            console.log('书去焦点');
            if(reg.test(this.value)){
                span.innerHTML = '用户名正确';
                span.className = 'success';
            }else{
                span.innerHTML = '用户名输入错误';
                span.className = 'error';
            }
        }

        let reg2 = /[_]/;
        console.log(reg2.test('_'));
    </script>
    <style>
        .success{
            color: green;
        }

        .error{
            color: red;
        }
    </style>
</body>
</html>